package com.travel.controller.open;

import com.travel.constant.ApiConstants;
import com.travel.model.dto.common.ApiResponse;
import com.travel.model.entity.content.Comment;
import com.travel.model.entity.content.Post;
import com.travel.service.Service.PostService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
//公开文章接口 , 获取所有文章, 获取文章详情, 获取文章评论
@Tag(name = "公开文章接口", description = "不需要登录就能访问的文章接口")
@RestController
@RequestMapping(ApiConstants.API_PUBLIC + "/posts")
@RequiredArgsConstructor
public class PublicPostController {
    
    private final PostService postService;

    @Operation(summary = "获取所有文章", description = "分页获取所有公开文章")
    @GetMapping
    public ApiResponse<Page<Post>> getAllPosts(Pageable pageable) {
        return ApiResponse.success("获取成功", postService.getAllPosts(pageable));
    }

    @Operation(summary = "获取文章详情", description = "根据ID获取文章详细信息")
    @GetMapping("/{id}")
    public ApiResponse<Post> getPost(
            @Parameter(description = "文章ID") @PathVariable Long id) {
        return ApiResponse.success("获取成功", postService.getPost(id));
    }
    
    @Operation(summary = "获取文章评论", description = "获取指定文章的所有评论")
    @GetMapping("/{postId}/comments")
    public ApiResponse<List<Comment>> getComments(
            @Parameter(description = "文章ID") @PathVariable Long postId) {
        return ApiResponse.success("获取成功", postService.getComments(postId));
    }
} 